const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show_page:false,
    is_apply:false,
    is_identity:false,
    search_lawyer_firm:"",
    status: '',
    lawyerId: "",
    lf_id: "",
    radio: "",
    columnsOffice: [], //律所
    current_page: 1, //律所当前页
    last_page: 1, //律所最后一页
    current_page_enterprise: 1, //企业列表当前页
    last_page_enterprise: 1, //企业列表最后一页
    type: "",
    domainColumn: [], //律所列表
    top_thumb_image: "",
    columns: ["男", "女"],
    provinceData: [],
    Practice: [],
    logo: [],
    district_id: "",
    city_id: "",
    province_id: "",
    street_id: "",
    identity_card_front: [],
    identity_card_backend: [],
    cityData: [],
    districtData: [],
    selectAddressData: [],
    streetShow: false,
    genderShow: false,
    isShowStreet: false,
    enterpriseShow:false,
    officeShow: false,
    jobShow: false,
    domainShow: false,
    agremment: false,
    pickerValue: [0, 0, 0],
    opren: false,
    minDate: new Date(1900, 1, 1),
    maxDate: new Date(2030, 12, 31),
    currentDate: new Date().getTime(),
    agreementShow: false,
    genderImg: {
      man: `${app.globalData.imgPath}debt/manNo.png`,
      women: `${app.globalData.imgPath}debt/womenNo.png`
    },
    form: {
      addressName: "",
      locationTitle: "",
      name: "",
      logo: "",
      job_name: "",
      job_no: "",
      identity_card_front: "",
      identity_card_backend: "",
      Practice: "",
      mobile: "",
      province: "",
      city: "",
      district: "",
      address: "",
      isDefault: false,
      desc: "",
      gender: '',
      domainColumn: [],
      job_time: '',
      job_year: "",
      office: "",
      point: "",
      street: "",
      detailed_address: "",
      logo_img:"",
      Practice_img:"",
      identity_card_front_img:"",
      identity_card_backend_img:"",
    },
    share: "",
    merchant_member_id:"",
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      }
      if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },
    enterpriseList:[],
    enterprise_radio:"",
    enterprise_name:"",
    imgPath: app.globalData.imgPath,
  },
  search_lawyer_firm(e){
    console.log(e)
    this.setData({search_lawyer_firm:e.detail});
    if(this.timer)clearTimeout(this.timer)
    this.timer = setTimeout(()=>{
      this.getLawyerOffice(this.data.search_lawyer_firm)
    },300)
  },
  goBack() {
    wx.navigateBack()
  },
  // onLoad: function (options) {
  //   //律所列表、擅长领域
  //   this.getCtegory();
  //   this.getLawyerOffice();

  //   //加载地址数据初始化
  //   this._initAddressInfo();
  //   this.getIsOpenAddress();
  //   if (options.type) {
  //     this.setData({
  //       type: options.type
  //     })
  //   }
  //   if(options.merchant_member_id){
  //     this.setData({
  //       merchant_member_id:options.merchant_member_id
  //     })
  //   }
  //   if (options.share == "lawyer" || options.share == 'office' || options.type == 'office' || options.type == 'lawyer') {
  //     this.setData({
  //       share: options.share,
  //     })
  //     this.checkLawyer();
  //   }
  //   if (options.type == 'office' || options.type == "lawyer") {
  //     if(options.type == 'office'){
  //         //企业列表
  //       this.getEnterprise()
  //     }
  //     this._getData()
  //   }
  //   if (options.type == "officedetail") {
  //     this._getDeatil()
  //   }
  //   if (options.type == "lawyerdetail") {
  //     this._getLawyerDeatil()
  //   }

  // },
  //企业
  chooseEnterprise(e){
    this.setData({enterprise_radio:e.currentTarget.dataset.id})
  },
  getEnterprise(){
    app._getNetWork({
      url: app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer-firm.verify"),
      success: (res) => {
        if(res.data.result == 1 && res.data.data.length!==0){
          let data = res.data.data.business_list.data;
            if(data.length==1){
              this.setData({
                enterprise_radio:data[0].id
              })
            }else{
              this.setData({
                enterpriseList:data,
                last_page_enterprise:res.data.data.business_list.last_page
              })

            }

        }
      }
    })
  },
  EnterprisePopup(e){
    let flag = e.currentTarget.dataset.flag;
    if(flag && this.data.enterprise_radio){
      let arr = this.data.enterpriseList.filter(item => item.id == this.data.enterprise_radio);
      this.setData({enterprise_name:arr[0].name})
    }
    this.setData({enterpriseShow:false})
  },

  checkLawyer() {
    let url = "";
    if (this.data.share == 'lawyer' || this.data.type == "lawyer") {
      url = 'plugin.lawyer-platform.frontend.controllers.lawyer.verify';
    } else {
      url = 'plugin.lawyer-platform.frontend.controllers.lawyer-firm.verify';
    }
    app._getNetWork({
      url: app.getNetAddresss(url),
      success: (res) => {
        if (res.data.result == 1) {
          if (this.data.share) {
            wx.navigateTo({
              url: '/packageI/lawyerPlatform/lawyerPlatform_index/index',
            })

          } else {
            this.setData({
              is_apply:res.data.data.is_apply,
              is_identity:res.data.data.is_identity
            })
            if(res.data.data.is_apply && res.data.data.is_identity){
              wx.navigateTo({
                url: '/packageI/lawyerPlatform/manage/manage?type=office',
              })
              return;
            }
            this.setData({show_page:true})
          }


        }
      }
    })
  },
  _getLawyerDeatil() {
    app._getNetWork({
      url: app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer.getDetail"),
      success: (res) => {
        if (res.data.result == 1) {
          let data = res.data.data.detail;
          let officeName = this.data.columnsOffice.filter(item => item.id == data.lf_id);
          this.data.logo.push({url: data.avatar_image})
          this.data.Practice.push({url: data.number_thumb_image})
          this.data.identity_card_backend.push({url: data.id_card_back_thumb_image})
          this.data.identity_card_front.push({url: data.id_card_front_thumb_image})
          this.data.domainColumn = data.category_data;
          this.data.domainColumn.forEach(item => item.status = true);
          this.data.form.point = {
            lng: data.location[0],
            lat: data.location[1]
          }
          let date = new Date(Number(data.start_time)),
            year = date.getFullYear(),
            month = date.getMonth() + 1,
            day = date.getDate();
          if (month < 10) {
            month = `0${month}`
          }
          if (day < 10) {
            day = `0${day}`
          }
          this.setData({
            "form.job_time": `${year}-${month}-${day}`
          })
          this.setData({
            lawyerId: data.id,
            province_id: data.address.province,
            city_id: data.address.city,
            district_id: data.address.area,
            logo: this.data.logo,
            Practice: this.data.Practice,
            identity_card_backend: this.data.identity_card_backend,
            identity_card_front: this.data.identity_card_front,
            "form.gender": data.gender == 1 ? '男' : '女',
            "form.name": data.name,
            "form.locationTitle": data.location_name,
            "form.mobile": data.tel,
            "form.job_year": data.year,
            "form.job_name": data.title,
            "form.job_no": data.number,
            "form.logo_img": data.avatar,
            "form.Practice_img": data.number_thumb,
            "form.identity_card_backend_img": data.id_card_back_thumb,
            "form.identity_card_front_img": data.id_card_front_thumb,
            "form.desc": data.introduction,
            "lf_id": data.lf_id,
            "form.office": officeName[0].name,
            "form.domainColumn": this.data.domainColumn,
            "form.addressName": data.show_address,
            "form.locationTitle": data.location_name,
            "form.point": this.data.form.point
          })
        }
      }
    })
  },
  getLawyerOffice(name="") {
    app._getNetWork({
      url: app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer.getLawyerFirm"),
      data:{name},
      success: (res) => {
        if (res.data.result == 1) {
          this.setData({
            columnsOffice: res.data.data.list.data,
            current_page: res.data.data.list.current_page,
            last_page: res.data.data.list.last_page
          })
        }
      }
    })
  },
  getCtegory() {
    app._getNetWork({
      url: app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer.getCategory"),
      success: (res) => {
        if (res.data.result == 1) {
          res.data.data.category.forEach(item => item.status = false)
          this.setData({
            domainColumn: res.data.data.category
          })
        }
      }
    })
  },
  _getDeatil() {
    let urlStr = app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer-firm.getDetail");
    app._postNetWork({
      url: urlStr,
      success: (res) => {
        let data = res.data.data.detail,
          province = wx.getStorageSync('provinceData'),
          city = wx.getStorageSync('cityData'),
          area = wx.getStorageSync('districtData'),
          provinceName = province.filter(item => item.id == data.address.province),
          cityName = city.filter(item => item.id == data.address.city),
          districtName = area.filter(item => item.id == data.address.area);

        let addressName = provinceName[0].areaname + cityName[0].areaname + districtName[0].areaname;
        this.data.logo.push({
          url: data.logo_image
        })
        this.data.Practice.push({
          url: data.thumb_image
        })
        this.setData({
          status: data.status,
          officeId: data.id,
          province_id: data.address.province,
          city_id: data.address.city,
          district_id: data.address.area,
          street_id: data.address.street,
          "form.name": data.name,
          "form.logo_img": data.logo,
          "form.Practice_img": data.thumb,
          logo: this.data.logo,
          radio: data.lf_id,
          Practice: this.data.Practice,
          "form.mobile": data.tel,
          "form.desc": data.introduction,
          "form.detailed_address": data.address_detail,
          "form.addressName": addressName
        })
        this._getStreet(data.address.area)
      }
    })
  },
  _getData() {
    let urlStr = app.getNetAddresss(
      "plugin.lawyer-platform.frontend.controllers.index.index");
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        if (res.data.result == 1) {
          let data = res.data.data,
            top_thumb_image = this.data.type == "office" ? data.set.lf_top_thumb_image : data.set.l_top_thumb_image;
          this.setData({
            top_thumb_image,
            l_content: res.data.data.set.l_content,
            l_status: res.data.data.set.l_status
          })
          wx.setNavigationBarTitle({
            title: data?data.set.diy_name: "律师平台"
          })
        }
      }
    })
  },
  onChangeStatus(event) {
    console.log(event)
    this.setData({
      status: event.detail,
    });
  },
  toggleGender(e) {
    let type = e.currentTarget.dataset.type;
    if (type == 'man') {
      this.data.genderImg.man = `${this.data.imgPath}debt/manYes.png`
      this.data.genderImg.women = `${this.data.imgPath}debt/womenNo.png`
    } else {
      this.data.genderImg.man = `${this.data.imgPath}debt/manNo.png`
      this.data.genderImg.women = `${this.data.imgPath}debt/womenYes.png`
    }
    this.setData({
      genderShow: false,
      genderImg: this.data.genderImg,
      "form.gender": type == "man" ? "男" : "女"
    })
  },
  onChange(event) {
    this.setData({
      agremment: event.detail,
    });
  },
  toGeolocation() {
    wx.navigateTo({
      url: "/packageC/o2o/o2oLocation_loc/o2oLocation_loc?tag=storeApply",
    });
  },
  chooseDomain(e) {
    let id = e.currentTarget.dataset.value.id;
    this.data.domainColumn.forEach(item => {
      if (item.id == id) {
        item.status = !item.status
      }
    });
    this.setData({
      domainColumn: this.data.domainColumn
    })
  },
  openDateLwtbtn: function () {
    this.setData({
      openDateLw: true,
    });
  },
  cancelDomain({
    target
  }) {
    this.data.form.domainColumn.splice(target.dataset.index, 1)
    this.data.domainColumn.forEach(item => {
      if (item.id == target.dataset.id) {
        item.status = false;
      }
    })
    this.setData({
      "form.domainColumn": this.data.form.domainColumn,
      domainColumn: this.data.domainColumn
    })
  },
  // 收货地址滚动事件
  bindChange: function (e) {
    var val = e.detail.value;
    if (this.data.pickerValue[0] != val[0]) {
      val[1] = 0;
      val[2] = 0;
    }
    if (this.data.pickerValue[1] != val[1]) {
      val[2] = 0;
    }
    this.setData({
      "pickerValue[0]": val[0],
      "pickerValue[1]": val[1],
      "pickerValue[2]": val[2],
    });
    this._initAddressInfo();
  },
  //地址选择器数据初始化
  _initAddressInfo: function () {
    var that = this;
    var _keyName = "provinceData";
    wx.getStorage({
      key: _keyName,
      success: function () {
        that._getProvinceData();
      },
      fail: function (res) {
        app._getNetWork({
          url: app.getNetAddresss("member.member-address.address"),
          success: function (res) {
            var response = res.data;
            var province = response.data.province;
            var city = response.data.city;
            var district = response.data.district;
            wx.setStorage({
              key: "provinceData",
              data: province,
            });
            wx.setStorage({
              key: "cityData",
              data: city,
            });
            wx.setStorage({
              key: "districtData",
              data: district,
            });
            that._initAddressInfo();
          },
          fail: function (res) {},
          state: true,
        });
      },
    });
  },
  //详细地址绑定输入
  addressinp: function (e) {
    let addressval = e.detail;
    this.setData({
      "form.detailed_address": addressval,
    });
  },
  //选择街道
  streetChoose() {
    if (this.data.form.addressName == '') {
      wx.showToast({
        icon: "none",
        title: "请先选择所在地区",
        duration: 1500,
      });
    } else {
      this.setData({
        streetShow: true,
        opren: false,
      });
    }
  },
  // 关闭选择收货地址
  _closeDateLw: function () {
    this.setData({
      openDateLw: false,
    });
  },
  _okAddress: function () {
    let seleData = this.data.selectAddressData;
    this.setData({
      "form.street": "",
      districtVal: "",
      district_id: seleData[2].id,
      city_id: seleData[1].id,
      province_id: seleData[0].id,
      "form.addressName": seleData[0].name + " " + seleData[1].name + " " + seleData[2].name,
      "form.province": seleData[0].name,
      "form.city": seleData[1].name,
      "form.district": seleData[2].name,
    });
    this._getStreet(seleData[2].id);
    this._closeDateLw();
  },
  afterRead(event) {
    wx.showLoading({
      title: '上传中'
    })
    const {
      file
    } = event.detail;
    let urlStr = app.getNetAddresss("upload.uploadPic"),
      type = event.currentTarget.dataset.type;
    wx.uploadFile({
      url: urlStr,
      filePath: file.url,
      name: 'file',
      success: (resdata) => {
        app.tips("上传成功")
        let res = JSON.parse(resdata.data);
        this.data[type].push({
          ...file,
          url: res.data.img_url,
          status: "done",
          message: '上传完成'
        });
        let form = `form.${type}`,img="";
        if(type == "logo"){
          img = "logo_img"
        }else if(type == 'Practice'){
          img = 'Practice_img'
        }else if(type == 'identity_card_front'){
          img ="identity_card_front_img"
        }else{
          img = 'identity_card_backend_img'
        }
        this.setData({
          [type]: this.data[type],
          [form]: res.data.img_url,
          [`form.${img}`]:res.data.img
        });
      },
      fail(err) {
        app.tips("上传成功")
        let fileList = [];
        fileList.push({
          ...file,
          url: '',
          status: "failed",
          message: '上传失败'
        });
        this.setData({
          fileList
        });
      },
      complete() {
        wx.hideLoading();
      }

    });
  },
  //删除logo图片
  delete(e) {
    let type = e.currentTarget.dataset.type
    this.setData({
      [type]: []
    })
  },
  //获取街道
  _getStreet(param) {
    var that = this;
    let urlStr = app.getNetAddresss("member.memberAddress.street");
    urlStr += "&district_id=" + param;
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1 && !app._isTextEmpty(res.data)) {
          if (this.data.street_id) {
            res.data.forEach(item => {
              if (item.id == this.data.street_id) {
                this.setData({
                  "form.street": item.areaname
                })
              }
            })
          }
          if (!app._isTextEmpty(res.data) && res.data.length > 0) {
            that.setData({
              districtVal: res.data,
              isShowStreet: true,
            });
          } else {
            that.setData({
              isShowStreet: false,
            });
          }
        } else {
          that.setData({
            isShowStreet: false,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  // 读取省key
  _getProvinceData: function () {
    var that = this;
    var _keyName = "provinceData";
    wx.getStorage({
      key: _keyName,
      success: function (res) {
        that.setData({
          provinceData: res.data,
        });
        that.setData({
          "selectAddressData[0].name": res.data[that.data.pickerValue[0]].areaname,
          "selectAddressData[0].id": res.data[that.data.pickerValue[0]].id,
          "selectAddressData[0].index": that.data.pickerValue[0],
        });
        that._getCityData();
      },
    });
  },
  // 读取城市key，筛选城市data
  _getCityData: function () {
    var _data = this.data.selectAddressData[0];
    var that = this;
    var _keyName = "cityData";
    wx.getStorage({
      key: _keyName,
      success: function (res) {
        var _json = [];
        for (var i = 0; i < res.data.length; i++) {
          if (res.data[i].parentid == _data.id) {
            _json.push(res.data[i]);
          }
        }
        that.setData({
          cityData: _json,
        });
        that.setData({
          "selectAddressData[1].name": _json[that.data.pickerValue[1]].areaname,
          "selectAddressData[1].id": _json[that.data.pickerValue[1]].id,
          "selectAddressData[1].index": that.data.pickerValue[1],
        });
        that._getDistrictData();
      },
    });
  },
  // 读取地区key，筛选地区data
  _getDistrictData: function () {
    var _data = this.data.selectAddressData[1];
    var that = this;
    var _keyName = "districtData";
    wx.getStorage({
      key: _keyName,
      success: function (res) {
        var _json = [];
        for (var i = 0; i < res.data.length; i++) {
          if (res.data[i].parentid == _data.id) {
            _json.push(res.data[i]);
          }
        }
        that.setData({
          districtData: _json,
        });
        that.setData({
          "selectAddressData[2].name": _json[that.data.pickerValue[2]].areaname,
          "selectAddressData[2].id": _json[that.data.pickerValue[2]].id,
          "selectAddressData[2].index": that.data.pickerValue[2],
        });
      },
    });
  },
  getIsOpenAddress() {
    var that = this;
    let urlStr = app.getNetAddresss("member.member-address.is-region");
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1 && !app._isTextEmpty(res.data)) {
          that.setData({
            is_region: res.data.is_region,
          });
        } else {
          console.log(res.msg);
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  // 关闭街道
  streetClose(e) {
    this.setData({
      streetShow: false,
      opren: true,
    });
  },
  //选择街道
  streetConfirm(e) {
    let strname = e.target.dataset.strname,
      id = e.target.dataset.id;
    this.setData({
      "street_id": id,
      "form.street": strname,
      streetShow: false,
    });
  },
  handle() {
    if (this.data.type == "office" || this.data.type == "officedetail") {
      this.submitOffice()
    }
    if (this.data.type == "lawyer" || this.data.type == "lawyerdetail") {
      this.submitLawyer()
    }
  },
  submitLawyer() {
    let json = {
      name: "请输入姓名",
      logo_img: "请上传头像",
      gender: "请选择性别",
      mobile: "请输入手机号",
      office: "请选择所属律所",
      domainColumn: "请选择擅长领域",
      job_year: "请输入执业年限",
      job_name: "请输入职称",
      job_no: "请输入执业证号",
      Practice_img: "请上传执业证照片",
      // identity_card_front_img: "请上传身份证人像面",
      // identity_card_backend_img: "请上传身份证国徽面",
      job_time: "请选择执业起始时间",
      desc: "请输入简介",
      addressName: "请选择服务区域",
      locationTitle: "请选择地理位置"
    };
    for (let key in json) {
      if (this.data.form[key] == "") {
        return app.tips(json[key]);
      }
    }
    if (!this.data.agremment && this.data.type == "lawyer" && this.data.l_status == 1) {
      return app.tips("请勾选阅读并同意协议");
    }
    let category_ids = [];
    this.data.domainColumn.forEach(item => {
      if (item.status) {
        category_ids.push(item.id)
      }
    })
    let start_time = this.data.form.job_time.replace(/-/g, ",");
    start_time = new Date(start_time).getTime()/1000;

    let form = {
      name: this.data.form.name,
      avatar: this.data.form.logo_img,
      gender: this.data.form.gender == "男" ? 1 : 2,
      tel: this.data.form.mobile,
      lf_id: this.data.radio || this.data.lf_id,
      category_ids,
      year: this.data.form.job_year,
      title: this.data.form.job_name,
      number: this.data.form.job_no,
      number_thumb: this.data.form.Practice_img,
      id_card_front_thumb: this.data.form.identity_card_front_img,
      id_card_back_thumb: this.data.form.identity_card_backend_img,
      start_time,
      introduction: this.data.form.desc,
      address: {
        area: this.data.district_id,
        city: this.data.city_id,
        province: this.data.province_id,
      },
      location: [this.data.form.point.lng, this.data.form.point.lat],
      location_name: this.data.form.locationTitle
    };

    let current_url = this.data.type == "lawyer" ? 'plugin.lawyer-platform.frontend.controllers.lawyer.apply' : 'plugin.lawyer-platform.frontend.controllers.lawyer.edit',
      dataForm = {
        form
      }
    if (this.data.type == "lawyerdetail") {
      dataForm.id = this.data.lawyerId
    }
    if (this.data.share == 'lawyer') {
      dataForm.form.merchant_member_id = this.data.merchant_member_id
    }

    let urlStr = app.getNetAddresss(current_url);
    app._postNetWork({
      url: urlStr,
      data: dataForm,
      success: (res) => {
        if (res.data.result == 1) {
          app.tips(res.data.msg)
          if (this.data.type == "lawyer" || this.data.type == "lawyerdetail") {
            wx.navigateBack()
          } else {
            wx.navigateTo({
              url: '/packageI/lawyerPlatform/lawyerPlatform_index/index',
            })
          }
        } else {
          app.tips(res.data.msg)
        }
      }
    });

  },
  cancelOffice() {
    this.setData({
      officeShow: false
    })
  },
  submitOffice() {
    let json = {
      name: "请输入律所名称",
      logo_img: "请上传logo",
      mobile: "请输入联系电话",
      desc: "请输入简介",
      Practice_img: "请上传资质",
      addressName: "请选择律所所在地址",
      detailed_address: "请输入详细地址",
      status: "请选择状态"
    };
    let form = {
      name: this.data.form.name,
      logo: this.data.form.logo_img,
      tel: this.data.form.mobile,
      thumb: this.data.form.Practice_img,
      introduction: this.data.form.desc,
      address: {
        area: this.data.district_id,
        city: this.data.city_id,
        province: this.data.province_id,
      },
      address_detail: this.data.form.detailed_address,
      status: this.data.status
    };
    if (this.data.isShowStreet) {
      json.stree = '请选择街道'
      form.address.street = this.data.street_id
    }
    for (let key in json) {
      if (this.data.form[key] == "") {
        return app.tips(json[key]);
      }
    }
    if (!this.data.agremment && this.data.type == "office" && this.data.l_status == 1) {
      return app.tips("请勾选阅读并同意协议");
    }
    let dataForm = {
      form,
    }
    if (this.data.type == "officedetail") {
      dataForm.id = this.data.officeId
    }
    if (this.data.type == 'office') {
      dataForm.form.merchant_member_id = this.data.merchant_member_id
      if(this.data.enterprise_radio){
        dataForm.form.business_id = this.data.enterprise_radio;
      }
    }
    let current_url = this.data.type == "office" ? "plugin.lawyer-platform.frontend.controllers.lawyer-firm.apply" : "plugin.lawyer-platform.frontend.controllers.lawyer-firm.edit";
    let urlStr = app.getNetAddresss(current_url);
    app._postNetWork({
      url: urlStr,
      data: dataForm,
      success: (res) => {
        if (res.data.result == 1) {
          app.tips(res.data.msg)
          if (this.data.type == "officedetail" || this.data.type == "office") {
            wx.navigateBack()
          } else {
            wx.navigateTo({
              url: '/packageI/lawyerPlatform/lawyerPlatform_index/index',
            })
          }
        } else {
          app.tips(res.data.msg)
        }
      }
    });
  },
  confirmOffice() {
    let result = this.data.columnsOffice.filter(item => item.id == this.data.radio);
    this.setData({
      officeShow: false,
      "form.office": result[0].name
    })
  },
  //律所列表加载更多
  bindscrolltolower() {
    if (this.data.current_page >= this.data.last_page) {
      return false;
    }
    let page = this.data.current_page + 1;
    app._getNetWork({
      url: app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer.getLawyerFirm"),
      data: {
        page
      },
      success: (res) => {
        if (res.data.result == 1) {
          this.data.columnsOffice = this.data.columnsOffice.concat(res.data.data.list.data);
          this.setData({
            columnsOffice: this.data.columnsOffice,
            current_page: res.data.data.list.current_page,
            last_page: res.data.data.list.last_page
          })
        }
      }
    })


  },
  //企业列表加载更多
  bindscrolltolowerEnterprise() {
    if (this.data.current_page_enterprise >= this.data.last_page_enterprise) {
      return false;
    }
    let page = this.data.current_page_enterprise + 1;
    app._getNetWork({
      url: app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.lawyer-firm.verify"),
      data: {
        page
      },
      success: (res) => {
        if (res.data.result == 1) {
          this.data.enterpriseList = this.data.enterpriseList.concat(res.data.data.business_list.data);
          this.setData({
            enterpriseList: this.data.enterpriseList,
            current_page_enterprise: res.data.data.business_list.current_page,
            last_page_enterprise: res.data.data.business_list.last_page
          })
        }
      }
    })
  },
  chooseOffice(event) {
    this.setData({
      radio: event.currentTarget.dataset.id,
      lf_id: event.currentTarget.dataset.id
    });
  },
  handleInput(e) {
    let value = e.detail,
      filed = e.target.dataset.filed,
      res = `form.${filed}`;
    if (filed == 'mobile' && (this.data.type == "lawyer" || this.data.type == "lawyerdetail")) {
      value = value.replace(/[^0-9]/g, '');
    }
    this.setData({
      [res]: value
    });
  },
  openPop({target}) {
    if(target.dataset.filed == 'enterpriseShow'){
      if(this.data.enterprise_radio){
        let arr = this.data.enterpriseList.filter(item => item.name == this.data.enterprise_name);
        this.setData({enterprise_radio:arr[0].id})
      }
    }
    this.setData({
      [target.dataset.filed]: true
    })
  },

  popConfirm({
    detail,
    target
  }) {
    let filed = target.dataset.filed;
    if (filed == "job_time") {
      let date = new Date(detail);
      let year = date.getFullYear(),
        month = date.getMonth() + 1,
        day = date.getDate();
      if (month < 10) {
        month = `0${month}`
      }
      if (day < 10) {
        day = `0${day}`
      }
      this.setData({
        "form.job_time": `${year}-${month}-${day}`
      })
    } else if (filed == 'domainColumn') {
      let domain = this.data.domainColumn.filter(item => item.status == true)
      this.setData({
        "form.domainColumn": domain
      })
    } else {
      this.setData({
        [`form.${filed}`]: detail.value,
      })

    }
    this.setData({
      [target.dataset.flag]: false
    })
  },
  closePop({
    target
  }) {
    if (target.dataset.flag == "domainShow") {
      this.data.domainColumn.forEach(item => item.status = false);
      this.setData({
        domainColumn: this.data.domainColumn
      });
    }
    this.setData({
      [target.dataset.flag]: false
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    let pages = getCurrentPages();
    let current_page = pages[pages.length-1];
    let options = current_page.options
    if (options.type) {
      this.setData({
        type: options.type,
        share: options.share||'',
        merchant_member_id:options.merchant_member_id || ''
      })
    }
    if(options.type == 'officedetail' || options.type == 'lawyerdetail'){
      this.setData({show_page:true})
    }
    if (options.share == "lawyer" || options.share == 'office' || options.type == 'office' || options.type == 'lawyer') {
       await  this.checkLawyer();
    }

    //律所列表、擅长领域
    this.getCtegory();
    this.getLawyerOffice();

    //加载地址数据初始化
    this._initAddressInfo();
    this.getIsOpenAddress();


    if (options.type == 'office' || options.type == "lawyer") {
      if(options.type == 'office'){
          //企业列表
        this.getEnterprise()
      }
      this._getData()
    }
    if (options.type == "officedetail") {
      this._getDeatil()
    }
    if (options.type == "lawyerdetail") {
      this._getLawyerDeatil()
    }

    var info = wx.getStorageSync('applyaddresspoint');
    this.setData({
      "form.locationTitle": info.address,
      "form.point": info.point
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})